package com.baseproject.rx.OnErrorHandler;

import com.baseproject.BaseProjectAppCofig;
import com.baseproject.BroadcastSender;
import com.baseproject.IRxSubscriberView;
import com.baseproject.datasource.ConfigParamsSubscriber;
import com.baseproject.util.LogUtils;

import rx.Observable;

import static com.baseproject.appconfig.AppConfigBaseProject.REQUEST_CODE_NONE_ORDER;

/**
 * Created by asus on 2017-09-12.
 */

public class NeedOrderErrorHandler extends BaseErrorHandler {

    public NeedOrderErrorHandler(Throwable e) {
        throwable = e;
    }

    @Override
    public void handleError(ConfigParamsSubscriber configParamsSubscriber, IRxSubscriberView iRxSubscriberView, IErrorStateListener iErrorStateListener) {
        int showOrderLevel = configParamsSubscriber.getIfShowOrderWhenNeededLevel();
        if (showOrderLevel != 0) {
            BroadcastSender.sendNeedOrder(iRxSubscriberView.getContext(), iRxSubscriberView.getPurpose()
                    , showOrderLevel);
            iErrorStateListener.haveShowOrder();
        }
        //更新已登录未订购状态
        BaseProjectAppCofig.getInstance().updateUserState(REQUEST_CODE_NONE_ORDER);
        LogUtils.logCatchedException(throwable, 2);
    }

    @Override
    public Observable<?> retry(int currentRetryTimes) {
        return Observable.error(throwable);
    }
}
